/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef PLANET_WARS_2D_RT_CORE_OBSERVER_ESSENTIAL_H
#define PLANET_WARS_2D_RT_CORE_OBSERVER_ESSENTIAL_H


#include "PlanetWars2dRT-core/utils/c_language.h"
#include "PlanetWars2dRT-core/utils/bool.h"


EXTERN_C_BEGIN


struct observer_t
{
  void (*handler)(void* an_observable,
		  void* observer_data,
		  void* event_data);
  void* data;
  void (*data_free)(void* this_data);
};

typedef struct observer_t observer_t;


void
observer_init_first_time_only_unsafe(observer_t* an_observer);

bool
observer_init_first_time_only(observer_t* an_observer);

void
observer_destructor_unsafe(observer_t* an_observer);

void
observer_destructor(observer_t* an_observer);

bool
observer_is_null(const observer_t* an_observer);

bool
observer_equals_unsafe(const observer_t* observer1, const observer_t* observer2);

bool
observer_equals(const observer_t* observer1, const observer_t* observer2);


struct observer_data_with_code
{
  unsigned short code;
  void* data;
};

typedef struct observer_data_with_code observer_data_with_code;


EXTERN_C_END


#endif
